home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: What happens on realloc() failure?
- Date: 22 Mar 1996 18:25:54 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4ivnfiINNdib@keats.ugrad.cs.ubc.ca>
- References: <Pine.SOL.3.91-941213.960322192958.24127A-100000@aidan.ncl.ac.uk>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <Pine.SOL.3.91-941213.960322192958.24127A-100000@aidan.ncl.ac.uk>,
- Tom Seddon <T.W.Seddon@ncl.ac.uk> wrote:
- >I am writing a program which will need to call realloc() a fair amount.
- >What I would like to know is whether the original data is still usable if
- >the realloc() fails. (Although it is unlikely that there will be problems
- >with running out of memory, it is possible that there will be problems due
- >to fragmentation of memory.)
-
- Read some reliable documentation (ISO standard, K&R2). If you had the K&R, you
- would know from page 252 that:
-
- realloc returns a pointer to the new space, or NULL if the
- request cannot be satisfied in which case [the pointer parameter]
- is not changed.
-
- >Since realloc() returns NULL on failure, is it safe to use the pointer to
- >the malloc()ed area I was trying to resize?
-
- Apparently so.
-
- >Or will the old area have
- >been freed by free() and now be unusable? What does the ANSI standard
- >have to say about this? I've never seen anything about this point before
-
- Presumably what I just said, since the K&R2 is quite faithful to the standard.
- --
-
-